package com.qf.config;

import org.springframework.context.annotation.*;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

/*
 *
 * @Configuration: 标记该类为配置类
 * @Bean: 方法注解， 作用： 把改方法的返回值注入到IOC容器中，默认的名称是 方法名
 *@EnableAspectJAutoProxy: 开启aop注解
 */
@Configuration
@PropertySource("classpath:jdbc.properties")
@ComponentScan({"com.qf.service", "com.qf.aop", "com.qf.dao"})
@EnableAspectJAutoProxy
@EnableTransactionManagement
@Import({JdbcConfig.class, MybatisConfig.class})
public class SpringConfig {


    @Bean("transactionManager")
    public TransactionManager createTransactionManager(DataSource dataSource){
        DataSourceTransactionManager tx = new DataSourceTransactionManager();
        tx.setDataSource(dataSource);
        return tx;
    }

}
